package com.qcu.exception;

import com.qcu.util.Response;
import com.qcu.util.ResponseCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Name: MyComputer
 * @ClassName GlobalExceptionHandler
 * @Description:
 * @date 2025/2/6 15:36
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(RepeatException.class)
    @ResponseBody
    public Response handleRepeatException(RepeatException e) {
        return Response.failure(ResponseCode.UNAUTHORIZED);
    }
    @ExceptionHandler(LimitRateNameIsNullException.class)
    @ResponseBody
    public Response handleLimitRateNameIsNullException(LimitRateNameIsNullException e) {
        return Response.failure(ResponseCode.FAILURE,"限流器key不能为空");
    }
    @ExceptionHandler(LimitRateException.class)
    @ResponseBody
    public Response handleLimitRateException(LimitRateException e) {
        return Response.failure(ResponseCode.LIMIT_RATE,e.getMessage());
    }

    @ExceptionHandler(LoginRequestParamterFailException.class)
    @ResponseBody
    public Response handleLoginRequestParamterFailException(LimitRateException e) {
        return Response.failure(ResponseCode.LIMIT_RATE,e.getMessage());
    }

}
